<?xml version="1.0"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">

  <xsl:template match="/">
    <xsl:variable name="print-a" select="(//fingerprint)[1]"/>
    <xsl:variable name="print-b" select="(//fingerprint)[2]"/>
    <xsl:variable name="package-a" select="(//fingerprint)[1]/@package-url"/>
    <xsl:variable name="package-b" select="(//fingerprint)[2]/@package-url"/>
    <xsl:variable name="docelem" select="/*"/>

    <html>
      <head>
        <title>ODF Fingerprint Difference Report</title>
        <style type="text/css"> tr.green td {background:#cfc;}  tr.red td {background:#fcc;}</style>
      </head>
      <body>
        <h1>ODF Fingerprint Difference Report</h1>
        <p>Between packages <tt>
            <xsl:value-of select="$package-a"/>
          </tt> and <tt>
            <xsl:value-of select="$package-b"/>
          </tt>.</p>
        <xsl:for-each select="distinct-values(//namespace/@name)">
          <xsl:variable name="ns" select="."/>
          <br/>
          <table border="1" width="80%">
            <tbody>
              <tr>
                <td colspan="3"> For Namespace <tt>
                    <xsl:value-of select="$ns"/>
                  </tt></td>
              </tr>
              <tr>
                <td>
                  <i>element name</i>
                </td>
                <td width="50%">
                  <xsl:value-of select="$package-a"/>
                </td>
                <td width="50%">
                  <xsl:value-of select="$package-b"/>
                </td>
              </tr>
              <xsl:for-each select="distinct-values($docelem//namespace[@name=$ns]/element/@name)">
                <xsl:variable name="lname" select="."/>
                <xsl:variable name="num-in-a"
                  select="number($print-a/namespace[@name=$ns]/element[@name=$lname]/@count)"/>
                <xsl:variable name="num-in-b"
                  select="number($print-b/namespace[@name=$ns]/element[@name=$lname]/@count)"/>
                <tr>
                  <xsl:attribute name="class">
                    <xsl:value-of select="if ($num-in-a eq $num-in-b) then 'green' else 'red'"/>                    
                  </xsl:attribute> 
                  <td>                   
                    <xsl:value-of select="$lname"/>
                  </td>
                  <td>                  
                    <xsl:value-of select="if (string($num-in-a) eq 'NaN') then '0' else $num-in-a"/>
                  </td>
                  <td>
                    <xsl:value-of select="if (string($num-in-b) eq 'NaN') then '0' else $num-in-b"/>
                  </td>
                </tr>
              </xsl:for-each>
            </tbody>
          </table>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>

</xsl:transform>
